/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2011 All Rights Reserved.
 */
package com.alipay.supergw.common.dal.share_supergw.manual.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.alibaba.common.lang.Paginator;
import com.alipay.supergw.common.dal.common.TddlHelper;
import com.alipay.supergw.common.dal.share_supergw.auto.daointerface.OutTransConfigDAO;
import com.alipay.supergw.common.dal.share_supergw.auto.dataobject.OutTransConfigDO;
import com.iwallet.biz.common.util.PageList;

/**
 * An ibatis based implementation of dao interface <tt>com.alipay.supergw.common.dal.share_supergw.auto.daointerface.OutTransConfigDAO</tt>.
 *
 * This file is generated by <tt>supergw-dalgen</tt>, a DAL (Data Access Layer)
 * code generation utility specially developed for <tt>supergw</tt> project.
 * 
 * PLEASE DO NOT MODIFY THIS FILE MANUALLY, or else your modification may
 * be OVERWRITTEN by someone else. To modify the file, you should go to 
 * directory <tt>(project-home)/dalgen</tt>, and 
 * find the corresponding configuration file (<tt>tables/sgw_out_trans_config.xml</tt>). 
 * Modify the configuration file according to your needs, then run <tt>supergw-dalgen</tt> 
 * to generate this file.
 */
public class IbatisOutTransConfigDAO extends SqlMapClientDaoSupport implements OutTransConfigDAO {

    /**
     *  Query DB table <tt>sgw_out_trans_config</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select out_trans_code_id, param_name, param_value, memo, gmt_create, gmt_modified from sgw_out_trans_config</tt>
     *
     *	@return List<OutTransConfigDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings("unchecked")
    public List<OutTransConfigDO> loadAll() throws DataAccessException {

        return getSqlMapClientTemplate().queryForList("MS-OUT-TRANS-CONFIG-LOAD-ALL", null);

    }

    /**
     *  Delete records from DB table <tt>sgw_out_trans_config</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>delete from sgw_out_trans_config where ((out_trans_code_id = ?) AND (param_name = ?))</tt>
     *
     *	@param outTransCodeId
     *	@param paramName
     *	@return int
     *	@throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public int delete(String outTransCodeId, String paramName) throws DataAccessException {
        Map param = new HashMap();

        param.put("outTransCodeId", outTransCodeId);
        param.put("paramName", paramName);

        return getSqlMapClientTemplate().delete("MS-OUT-TRANS-CONFIG-DELETE", param);
    }

    /**
     *  Query DB table <tt>sgw_out_trans_config</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select out_trans_code_id, param_name, param_value, memo, gmt_create, gmt_modified from sgw_out_trans_config where ((out_trans_code_id = ?) AND (param_name = ?))</tt>
     *
     *	@param outTransCodeId
     *	@param paramName
     *	@return OutTransConfigDO
     *	@throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public OutTransConfigDO selectByOutTransCodeIdAndParamName(String outTransCodeId,
                                                               String paramName)
                                                                                throws DataAccessException {
        Map param = new HashMap();

        param.put("outTransCodeId", outTransCodeId);
        param.put("paramName", paramName);

        return (OutTransConfigDO) getSqlMapClientTemplate().queryForObject(
            "MS-OUT-TRANS-CONFIG-SELECT-BY-OUT-TRANS-CODE-ID-AND-PARAM-NAME", param);

    }

    /**
     *  Update DB table <tt>sgw_out_trans_config</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>update sgw_out_trans_config set param_value=?, memo=?, gmt_modified=sysdate where ((out_trans_code_id = ?) AND (param_name = ?))</tt>
     *
     *	@param paramValue
     *	@param memo
     *	@param outTransCodeId
     *	@param paramName
     *	@return int
     *	@throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public int update(String paramValue, String memo, String outTransCodeId, String paramName)
                                                                                              throws DataAccessException {
        Map param = new HashMap();

        param.put("paramValue", paramValue);
        param.put("memo", memo);
        param.put("outTransCodeId", outTransCodeId);
        param.put("paramName", paramName);

        return getSqlMapClientTemplate().update("MS-OUT-TRANS-CONFIG-UPDATE", param);
    }

    /**
     *  Insert one <tt>OutTransConfigDO</tt> object to DB table <tt>sgw_out_trans_config</tt>, return primary key
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>insert into sgw_out_trans_config(out_trans_code_id,param_name,param_value,memo,gmt_create,gmt_modified) values (?, ?, ?, ?, sysdate, sysdate)</tt>
     *
     *	@param outTransConfig
     *	@return String
     *	@throws DataAccessException
     */
    public String insert(OutTransConfigDO outTransConfig) throws DataAccessException {
        if (outTransConfig == null) {
            throw new IllegalArgumentException("Can't insert a null data object into db.");
        }

        getSqlMapClientTemplate().insert("MS-OUT-TRANS-CONFIG-INSERT", outTransConfig);

        return outTransConfig.getOutTransCodeId();
    }

    /**
     *  Query DB table <tt>sgw_out_trans_config</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select f.out_trans_code_id, f.param_name, f.param_value, f.memo, f.gmt_create, f.gmt_modified from sgw_out_trans_code t, sgw_out_trans_config f, sgw_transtype_channel_map m</tt>
     *
     *	@param outTransCode
     *	@param channelSystemId
     *	@param paramName
     *	@param pageSize
     *	@param pageNum
     *	@return PageList
     *	@throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public PageList select(String outTransCode, String channelSystemId, String paramName,
                           int pageSize, int pageNum) throws DataAccessException {

        Map param = new HashMap();

        param.put("outTransCode", outTransCode);
        param.put("channelSystemId", channelSystemId);
        param.put("paramName", paramName);
        param.put("pageSize", new Integer(pageSize));
        param.put("pageNum", new Integer(pageNum));

        Paginator paginator = new Paginator();
        paginator.setItemsPerPage(pageSize);
        paginator.setPage(pageNum);

        TddlHelper.skipSqlParse();
        paginator.setItems(((Integer) getSqlMapClientTemplate().queryForObject(
            "MS-OUT-TRANS-CONFIG-SELECT-COUNT-FOR-PAGING", param)).intValue());

        PageList pageList = new PageList();
        pageList.setPaginator(paginator);

        if (paginator.getBeginIndex() <= paginator.getItems()) {
            param.put("startRow", new Integer(paginator.getBeginIndex() == 0 ? 0 : paginator
                .getBeginIndex() - 1));
            param.put("endRow", new Integer(10));

            TddlHelper.skipSqlParse();
            pageList.addAll(getSqlMapClientTemplate().queryForList("MS-OUT-TRANS-CONFIG-SELECT",
                param));
        }

        return pageList;
    }

    /**
     *  Query DB table <tt>sgw_out_trans_config</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select f.out_trans_code_id, f.param_name, f.param_value, f.memo, f.gmt_create, f.gmt_modified from sgw_out_trans_code t, sgw_out_trans_config f, sgw_transtype_channel_map m</tt>
     *
     *	@param outTransCode
     *	@param channelSystemId
     *	@param paramName
     *	@return List<OutTransConfigDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public List<OutTransConfigDO> selectNoPage(String outTransCode, String channelSystemId,
                                               String paramName) throws DataAccessException {
        Map param = new HashMap();

        param.put("outTransCode", outTransCode);
        param.put("channelSystemId", channelSystemId);
        param.put("paramName", paramName);

        TddlHelper.skipSqlParse();
        return getSqlMapClientTemplate().queryForList("MS-OUT-TRANS-CONFIG-SELECT-NO-PAGE", param);

    }

}